/**
 * 功能描述 行编辑触发事件
 */
define(function (require, exports, module) {
	var store = require("store");
	var activeUser = store.get("user");
	var aw = require("ajaxwrapper");
	var Dialog=require("dialog");
	
    module.exports = {
        addApply : function(widget){
        	var form = widget.get("form");
        	var applyForm = widget.get("perform");
        	
        	widget.hide([".J-form", ".J-pergrid"]).show(".J-perform");
        	if(widget.get("type") == "NonMember"){
        		applyForm.show("personalInfo.idNumber").hide(["idNumberSearch"]);
        		widget.get("subnav").hide(["servicePoint", "startDate", "save", "add","return"]);
        	}else{
        		applyForm.hide("personalInfo.idNumber").show(["idNumberSearch"]);
        		widget.get("subnav").hide(["save", "return"]);
        	}
			applyForm.reset();
			var autocomplete =  $("input[name='travelContractObj']",applyForm.element).data("autocompleter");
			if(form.getValue("tourType") == "IndivMember"){
				applyForm.hide("personalInfo.name").show(["memberObj", "travelContractObj"]);
				applyForm.setValue("member", true);
				applyForm.setValue("customer", false);
			}else{
				applyForm.show("personalInfo.name").hide(["memberObj", "travelContractObj"]);
				applyForm.setValue("member", false);
				applyForm.setValue("customer", false);
			}
			
        },
        editApply : function(data, widget){
        	var applyForm = widget.get("applyForm");
        	
        	widget.hide([".J-form", ".J-applygrid"]).show(".J-applyform");
			widget.get("subnav").show(["applyCancel"]).hide(["travelDate", "destination", "servicePoint","cancel"]);
			applyForm.reset();
			applyForm.setData(data);
			var pkPlanItem = widget.get("form").getValue("pkPlanItem");
			var pkServicePoint = widget.get("form").getValue("pkServicePoint");
			applyForm.setValue("pkPlanItem",pkPlanItem);
			applyForm.setValue("pkServicePoint",pkServicePoint);
			
			applyForm.setValue("travelContractObj",data.travelContract);
			applyForm.setValue("pkTravelContract",data.travelContract.pkTravelContract);
			
			var memberObj = {
				personalInfo:data.personalInfo
			};
			applyForm.setValue("memberObj",memberObj);
			
			if(data.member == "false" || data.member==false){
				applyForm.hide("memberObj").show("personalInfo.name");
			}else{
				applyForm.show("memberObj").hide("personalInfo.name");
				applyForm.setReadonly("personalInfo.idNumber",true);
				applyForm.setReadonly("personalInfo.mobilePhone",true);
				applyForm.setReadonly("personalInfo.sex",true);
			}

			var autocomplete =  $("input[name='travelContractObj']",applyForm.element).data("autocompleter");
			autocomplete.setExtraParam("pkServicePoint",widget.get("subnav").getValue("servicePoint"));
			
        },
        deleteApply:function(data,widget,index){
        	if(data.pkSignUpRoom){
        		aw.del("api/signuproom/"+data.pkSignUpRoom+"/delete",function(data){
        			widget.get("pereditgrid").remove(index);
        			//widget.get("form").setValue("signUpNumber",widget.get("pereditgrid").getData().length)
        		});
        	}else{
        		widget.get("pereditgrid").remove(index);
        	}
        },
        deleteMem:function(data,widget,index){
        	if(data.pkSignUpRoom){
        		aw.del("api/signuproom/"+data.pkSignUpRoom+"/delete",function(data){
        			widget.get("pergrid").remove(index);
        			//widget.get("form").setValue("signUpNumber",widget.get("pereditgrid").getData().length)
        		});
        	}else{
        		widget.get("pergrid").remove(index);
        	}
        }
    };
});
